package com.jz.utils;

import javax.servlet.http.Part;
import java.io.File;
import java.io.IOException;

public class FileUploadUtils {
    public static String upload(Part part,String path){
        //获取文件名
        String fileName = part.getSubmittedFileName();
        //文件名重命名
        long l = System.currentTimeMillis();
        fileName = l+fileName;
        //判断本地硬盘是否存在
        File file = new File(path);
        if (!file.exists()){
            file.mkdirs();
        }
        //上传
        try {
            part.write(path+File.separator+fileName);
            return fileName;
        } catch (IOException e) {
            throw new RuntimeException();
        }
    }
}
